import os
import fasttext as ft


class Model:
    """Load model and predicting"""

    def __init__(self):
        curr_path = os.path.join(os.path.abspath('.'), 'models')
        self.model = ft.load_model(os.path.join(curr_path, 'ft_ai100.bin'))

    def predict(self, input_str):
        res = self.model.predict(input_str, k=1)
        rtn = {
            'label': res[0][0][9:],
            'probability': res[1][0]
        }
        return rtn


